#!/usr/bin/perl
# 
#  Exercise 6.7 
# 
# Write a module that contains subroutines that report various statistics on DNA 
# sequences, for instance length, GC content, presence or absence of poly-T 
# sequences (long stretches of mostly T's at the 5' (left) end of many $DNA 
# sequences), or other measures of interest.
#
# Answer to Exercise 6.7

# To use as a module, save this in a file called, for instance,
# "exer0607.pm".

# Here's an example of a main program that would call the module.
# Save everything between the '########' lines, and remove the
# '# ' at the beginning of each line 

##############################
# #!/usr/bin/perl
# 
# use strict;
# use warnings;
# use exer0607;
# 
# my $DNA = 'TTATTTTTTTGTTTTTTTTACGTACGTACGTACGTGACGACGTACGTA';
# 
# print DNA_length($DNA),"\n";
# print DNA_GC_content($DNA), "\n";
# print DNA_has_poly_T($DNA), "\n";
# 
# exit;
##############################

sub DNA_length {

	my($dna) = @_;

	return length $dna;
}

sub DNA_GC_content {

	my($dna) = @_;

	my $gc = ($dna =~ tr/GCgc//);

	return "$gc/" . length $dna;
}

sub DNA_has_poly_T {

	my($dna) = @_;

	# We'll need at least 10 T's out of the last 12 bases

	my $head = substr($dna, 0, 12);

	my $countT = ($head =~ tr/Tt//);

	if($countT >= 10) {
		return $countT;
	}else{
		return 0;
	}
}
	
# Remember that a module needs to have the following line at the end!
1;
